import Vue from 'vue'
import dataSource from 'mars-pro/src/pro/mixins/dataSource'
import {getComponentByUrl} from './modals/index'
import {vRequired} from 'mars-pro/src/pro/rule'
import previewTemplates from './components/preview-templates'
export default new Vue({
    mixins: [
        dataSource('dataSourceList', '/mock/api/code-gen/data-source/find', {dataField: 'data', freeze: true}),
        dataSource('dataSetList', '/mock/api/code-gen/data-set/find', {dataField: 'data', freeze: true}),
        //数据库接口配置
        dataSource('dbConfig', '/mock/api/code-gen/db/find', {dataField: 'data', freeze: true}),
        //数据集
        dataSource('dataSet', '/mock/api/code-gen/data-set/find', {dataField: 'data', freeze: true}),
    ],
    data() {
        this.vStrRequired = vRequired('不能为空')
        this.previewTemplates = previewTemplates
        return {
            // 规范配置
            config: {
                dictData: {
                    YES_OR_NOT: [
                        { label: "非空", value: "1" }
                    ],
                    UI_TYPE: [
                        { label: "联想输入", value: "input-autocomplete" },
                        { label: "日期段", value: "input-date-range" },
                        { label: "日期", value: "input-date" },
                        { label: "日期时间", value: "input-datetime" },
                        { label: "邮箱", value: "input-email" },
                        { label: "数字段", value: "input-number-range" },
                        { label: "数字", value: "input-number" },
                        { label: "正则文本", value: "input-pattern" },
                        { label: "联系方式", value: "input-phone" },
                        { label: "文本输入", value: "input-text" },
                        { label: "多行文本", value: "input-textarea" },
                        { label: "时间段", value: "input-time-range" },
                        { label: "时间", value: "input-time" },
                        { label: "下拉级联", value: "select-cascader" },
                        { label: "复选", value: "select-checks" },
                        { label: "下拉分组", value: "select-grouplist" },
                        { label: "下拉列表", value: "select-list" },
                        { label: "单选", value: "select-radios" },
                        { label: "下拉表格", value: "select-table" },
                        { label: "标签选择", value: "select-tags" },
                        { label: "下拉树", value: "select-tree" } 
                    ]
                },
                dictFieldMap: { label: "name", value: "code" },
                getDataByDictType: null,
                //detailModel--label命名规范
                //getLabelPropFromDetailModel: (prop) => prop + "AsText",

                authorityData: {},
                useInfoData: {},
                getComponentByUrl: getComponentByUrl,
                api: {
                    totalField: "total",
                    pageSizeField: "pageSize",
                    currentPageField: "currentPage",
                    dataField: "",
                    singleQueryField: "query",
                },
            },
            selectPreviewTemplate: null,
            // 当前数据集
            currentDataSet: {
                name: '新建数据集',
                _id: null,
                datas: []
            }
        }
    },
    methods: {},
    computed: {
        previewTemplatesDataSource(){
            return Object.keys(previewTemplates).map((v) => ({
                value: v,
                label: previewTemplates[v].title
            }))
        }
    }
})